import commonjs from '@rollup/plugin-commonjs';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import typescript from 'rollup-plugin-typescript2';
import vue from 'rollup-plugin-vue';
import postcss from 'rollup-plugin-postcss';
import external from 'rollup-plugin-peer-deps-external';
import babel from '@rollup/plugin-babel';
import json from '@rollup/plugin-json';

import autoprefixer from 'autoprefixer';

import pkg from './package.json';
// import { readFileSync } from 'fs'
// const pkgStr = readFileSync("./package.json").toString()
// const packageJson = JSON.parse(pkgStr)
// packageJson.main = 'zw-preview-phone.umd.js'
const extensions = ['.vue', '.ts', '.js', '.tsx', '.less'];
export default {
    input: 'src/index.ts',
    output: [
        {
            file: pkg.main,
            format: 'umd',
            name: pkg.name,
            exports: 'named',
            sourcemap: true,
            globals: {
                vue: 'Vue'
            }
        },
        {
            file: pkg.module,
            format: 'es',
            exports: 'named',
            sourcemap: true
        }
    ],
    plugins: [
        // dts({
        //     compilerOptions: {
        //         "preserveSymlinks": false
        //     }
        // }),
        vue({
            preprocessStyles: true
        }),
        postcss({
            extensions: ['.css', '.scss', '.sass'],
            // extract: 'index.css',
            plugins: [autoprefixer()]
        }),
        typescript({
            useTsconfigDeclarationDir: true
        }),
        commonjs(),
        nodeResolve(),
        external(),
        babel({
            presets: ['@babel/preset-typescript'],
            plugins: ['@vue/babel-plugin-jsx'],
            babelHelpers: 'bundled',
            extensions: extensions
        }),
        json()
    ],
    external: ['element-plus', 'axios']
};
